<?php

namespace App\Http\Middleware;

use App\Exceptions\ApiException;
use Closure;
use Cache;

class Authenticate
{
    /**
     * handle
     *
     * @param         $request
     * @param Closure $next
     *
     * @author chenxuyi
     * @return mixed
     * @throws ApiException
     */
    public function handle($request, Closure $next)
    {
        $token = $request->get('token', null);
        $info  = Cache::get($token);
        if (!$token || !$info) {
            throw new ApiException('登录已过期，请重新登录');
        }

        return $next($request);
    }
}
